﻿using System;

namespace MiniFox.Log
{
    /// <summary>
    /// 日志内容
    /// </summary>
    public abstract class LogContent
    {
        string _logId;
        /// <summary>
        /// 
        /// </summary>
        public LogContent() : this(SequenceGUID.NewGUID())
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="logId"></param>
        protected LogContent(string logId)
        {
            _logId = logId;
        }
        /// <summary>
        /// 
        /// </summary>
        public string LogID
        {
            get { return _logId; }
        }
        /// <summary>
        /// 
        /// </summary>
        public Exception Exception { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string ErrorCode
        {
            get
            {
                if (Exception == null)
                    return null;
                var e = Exception as MiniFox.Exceptions.SystemException;
                if (e == null)
                    return MiniFox.Exceptions.SystemException.ERROR_CODE;
                return e.ErrorCode;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public virtual string ExceptionMessage
        {
            get
            {
                if (Exception == null)
                    return null;
                Exception exception = this.Exception;
                while (exception.InnerException != null)
                {
                    exception = exception.InnerException;
                }
                return exception.ToString();
            }
        }

    }
    /// <summary>
    /// 
    /// </summary>
    public class DefaultLogContent : LogContent
    {
        /// <summary>
        /// 
        /// </summary>
        public string Message
        {
            get;
            set;
        }
    }
    
}
